<script>
import { userTransfer } from './api'
import customer from '@/views/index/customer.vue'
export default {
  name: '',
  props: { leadId: '' },
  components: { customer },
  data() {
    return {
      customerId: '',
    }
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    change(row) {
      this.customerId = row.id
      this.externalUserid = row.externalUserid
    },
    submit() {
      this.$dialog
        .confirm({
          title: '关联线索',
          message: '线索关联后不可取消，是否确认关联?',
        })
        .then(() => {
          let params = {
            leadId: this.leadId,
            customerId: this.customerId,
            externalUserid: this.externalUserid,
          }
          const toast = this.$toast.loading()
          userTransfer(params)
            .then((res) => {
              this.cancel()
              this.$toast.success('操作成功')
            })
            .finally(() => {
              toast.clear()
            })
        })
    },
    cancel() {
      this.$emit('input', false)
    },
  },
}
</script>

<template>
  <van-popup
    v-bind="$attrs"
    position="right"
    :overlay-style="{ backgroundColor: 'rgba(0, 0, 0, 0.6)' }"
    style="width:95%;height:100%"
    :close-on-click-overlay="false"
  >
    <div class="content">
      <customer isSelectCustomer @change="change"></customer>

      <div class="footer flex" style="margin: 20px;">
        <van-button class="" native-type="button" round block plain @click="cancel">取消</van-button>
        <van-button type="info" native-type="submit" round block class="ml10" @click="submit">提交</van-button>
      </div>
    </div>
  </van-popup>
</template>

<style lang="less" scoped>
.content {
  height: 100%;
  display: flex;
  flex-direction: column;
}
</style>
